package bb.lanxing.lib.devices.base.converter;

import android.bluetooth.BluetoothGattCharacteristic;

import java.util.UUID;

import bb.lanxing.lib.devices.base.CharacteristicConverter;
import bb.lanxing.lib.devices.ble.BLEAttributes;
import bb.lanxing.lib.devices.core.ble.IGattClient;

public abstract class Cadence01Converter implements CharacteristicConverter {
    public abstract void onCadenceData(int deviceType, int sumWheel, int wheelTime, int sumCadence, int cadenceTime, int pressure, int temperature);

    @Override
    public final void convert(IGattClient iGattClient, BluetoothGattCharacteristic bluetoothGattCharacteristic) {
        if (bluetoothGattCharacteristic.getUuid().equals(UUID.fromString(BLEAttributes.BLE_CADENCE_MEASUREMENT))) {
            int intValue = bluetoothGattCharacteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
            int i7 = 1;
            int sumWheel;
            int wheelTime;
            if ((intValue & 1) > 0) {
                sumWheel = bluetoothGattCharacteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, 1);
                wheelTime = bluetoothGattCharacteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 5);
                i7 = 7;
            } else {
                sumWheel = -1;
                wheelTime = -1;
            }
            int sumCadence;
            int cadenceTime;
            if ((intValue & 2) > 0) {
                sumCadence = bluetoothGattCharacteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, i7);
                cadenceTime = bluetoothGattCharacteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, i7 + 2);
            } else {
                sumCadence = -1;
                cadenceTime = -1;
            }
            onCadenceData(iGattClient.getType(), sumWheel, wheelTime, sumCadence, cadenceTime, 0, 0);
        }
    }
}